<?php

class Conexion {

    private $userdb;
    private $passdb;
    private $hostdb;
    private $db;
    private $conexion;
    private static $instance = false;

    private function __construct() {
        $this->userdb = "root";
        $this->passdb = "";
        $this->hostdb = "localhost";
        $this->db = "telecomi_gesis";
    }

    public static function getInstance() {
        if (!self::$instance instanceof self) {
            self::$instance = new self;
        }
        return self::$instance;
    }

    public function conectar() {
        $this->conexion = mysql_connect($this->hostdb, $this->userdb, $this->passdb);
        
        mysql_select_db($this->db);
    }

    public function consulta($consulta) {
        $this->conectar();
        $res = mysql_query($consulta, $this->conexion);
        $res = $this->arrayResultado($res);
        return $res;
    }

    public function contarFilas($res) {
        return mysql_numrows($res);
    }

    public function arrayResultado($res) {
        $retorno = array();
        if (!is_bool($res)) {
            while ($fila = mysql_fetch_array($res)) {
                array_push($retorno, $fila);
            }
            return $retorno;
        }
    }

    public function obtenerUltimoID() {
        return mysql_insert_id($this->conexion);
    }

}

?>
